/**@FILE:ApplyReturnAction.java
 * @AUTHOR:qingsheng.zheng
 * @DATE:2015-2-10 下午11:24:01*/
package com.xf.toy.web;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.xf.pub.exception.ServiceException;
import com.xf.pub.logger.LoggerUtil;
import com.xf.toy.bean.ApplyReturn;
import com.xf.toy.dao.page.Pagination;
import com.xf.toy.service.ApplyReturnService;
import com.xf.toy.service.constant.ToyConst;
import com.xf.toy.web.common.BaseAction;

/*******************************************
 * @COMPANY:alibaba
 * @CLASS:ApplyReturnAction
 * @DESCRIPTION:	
 * @AUTHOR:qingsheng.zheng
 * @VERSION:v1.0
 * @DATE:2015-2-10 下午11:24:01
 *******************************************/
@Controller
@RequestMapping(value = "/toy/applyreturn")
public class ApplyReturnAction extends BaseAction {
	@Resource(name = "applyReturnService")
	private ApplyReturnService applyReturnService;
	private Long userid;

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public void applyList(
			@RequestParam(required = false) Integer pageNo,
			@RequestParam(required = false) Integer pageSize,
			HttpServletRequest req,
			HttpServletResponse resp) {
		try {
			Pagination page = new Pagination();
			if (pageNo != null) {
				page.setPageSize(pageSize);
				page.setCurrentPage(pageNo);
			}
			userid=super.getUserId(req);
			operLogger.info(LoggerUtil.logstr("method","toy/applyreturn/list","userid",userid+""));
			String status=ToyConst.TOY_APPLY_RETURN_Y;
			ApplyReturn app=new ApplyReturn();
			app.setStatus(status);
			List<ApplyReturn> values=applyReturnService.selectApplyList(app,page);
			response(resp, values);
		} catch (ServiceException e) {
			response(resp, e);
		}
	}
	
	@RequestMapping(value = "/apply")
	public void applyReturn(
			 Long userid,
			 Long orderid,
			 String toycode,
			HttpServletRequest req,
			HttpServletResponse resp) {
		try {
			operLogger.info(LoggerUtil.logstr("method","toy/applyreturn/apply","userid",userid+""));
			String status=ToyConst.TOY_APPLY_RETURN_Y;
			ApplyReturn app=new ApplyReturn();
			app.setApplytime(new Date());
			app.setOrderId(orderid);
			app.setUserId(userid);
			app.setStatus(status);
			app.setToyCode(toycode);
			app.setUpdatetime(new Date());
			applyReturnService.applyReturn(app);
			response(resp, null);
		} catch (ServiceException e) {
			response(resp, e);
		}
	}

}

